package com.ymatou.shop.ui.view;

import com.ymatou.shop.R;
import com.ymatou.shop.cache.ImageCache;
import com.ymatou.shop.model.Product;
import com.ymatou.shop.util.GlobalUtil;
import com.ymatou.shop.util.LogUtil;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

public final class ImageFragment extends Fragment {

	public static ImageFragment newInstance(Product p, Context c) {
		ImageFragment fragment = new ImageFragment();
		fragment.product = p;
		fragment.context = c;
		return fragment;
	}

	private Product product;
	private Context context;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View layout = inflater.inflate(R.layout.home_item, null);

		final ImageView mImageView = (ImageView) layout.findViewById(R.id.product_imageviwe);
//		mImageView.setImageResource(R.drawable.back_icon);

		Drawable drawable = ImageCache.get(context, product.mHomePic, new ImageCache.OnIconLoadCompleteListener() {
			@Override
			public void onLoadComplete(String url, boolean success, Drawable drawable) {
				if (success) {
					mImageView.setImageDrawable(drawable);
				}
			}
		});
		if (drawable != null) {
			mImageView.setImageDrawable(drawable);
		}
		//        layout.addView(mImageView);
		mImageView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				GlobalUtil.startEventListActivity(v.getContext(), product.mSellerId);
				
			}
		});
		return layout;
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		//        outState.putString(KEY_CONTENT, mContent);
	}
}
